//
//  NSObjectCLBase.m
//  CLBasicsDemo
//
//  Created by 小草毋正 on 2017/9/13.
//  Copyright © 2017年 zbw. All rights reserved.
//

#import "NSObjectCLBase.h"
#import <objc/runtime.h>


@implementation NSObjectCLBase



+ (NSMutableArray<NSString *> *)propertyNamesIgnore:(NSArray<NSString *> *)ignoreProperties {
    return [[self alloc] propertyNamesIgnore:ignoreProperties];
}

+ (NSMutableArray<NSString *> *)properties {
    return [[self alloc] propertieNames];
}

- (NSMutableArray<NSString *> *)propertyNamesIgnore:(NSArray<NSString *> *)ignoreProperties {
    NSMutableArray *properties = [self propertieNames];
    for (NSString *property in ignoreProperties) {
        [properties removeObject:property];
    }
    return properties;
}

- (NSMutableArray<NSString *> *)propertieNames {
    u_int count;
    NSMutableArray *propertiesMArray = [[NSMutableArray alloc] init];
    objc_property_t *properties  = class_copyPropertyList([self class], &count);
    for(int index = 0; index < count; index ++){
        const char* propertyName = property_getName(properties[index]);
        [propertiesMArray addObject: [NSString stringWithUTF8String: propertyName]];
    }
    free(properties);
    return propertiesMArray;
}



@end




